<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/27
 * Time: 9:25
 */
namespace app\api\controller;
use app\common\business\User as UserBis;
class User extends AuthBase {
    public function index()
    {
        $user = (new UserBis())->getNormalUserId($this->userId);
        $resultUser = [
            "id" => $user['id'],
            'username'=>$user['username'],
            'sex'=>$user['sex']
        ];
        return show(config("status.success"),'ok',$resultUser);
    }
    public function update(){
        $username = input('username','','trim');
        $sex = input("sex",'','intval');
        $data = [
            'username' =>$username,
            'sex' =>$sex
        ];
        $validate = (new \app\api\validate\User())->scene('update_user');
        if(!$validate->check($data)){
            return show(config("status.error"),$validate->getError());
        }
        $userBisObj = new UserBis();
        $user = $userBisObj->update($this->userId,$data,$this->accessToken);
        dump($user);
        if(!$user){
            return show(config('status.error'),'更新数据失败');
        }
        return show(1,'ok');
    }
}